#pragma once

#include "opencv_test.hpp"
#include "opencv_read.hpp"
#include "opencv_basic.hpp"
#include "opencv_resize.hpp"
#include "opencv_draw.hpp"
#include "opencv_perspective.hpp"
#include "opencv_color_detection.hpp"
#include "opencv_shape_detection.hpp"
#include "opencv_face_detection.hpp"
#include "opencv_virtual_painter.hpp"

#include <iostream>
#include <string>
#include <direct.h>

namespace opencv_course_entry
{
    /// 预处理主要是获得当前的资源位置
    std::string preprocess()
    {
        char *buffer; // Getthecurrentworkingdirectory:获得当前运行的路径
        {
            if ((buffer = _getcwd(NULL, 0)) == NULL)
                perror("_getcwderror");
            std::cout << "current running dir ::" << buffer << std::endl;
        }
        std::string resDir; // 当前资源目录
        {
            resDir = buffer;
            // resDir += "/../../resource/";
            resDir += "/resource/";
            std::cout << "current resource dir ::" << resDir << std::endl;
        }
        std::string imgPath; // 当前测试图片：
        {
            imgPath = resDir + "test_image.png";
            // imgPath=resDir+filename;
            std::cout << "current test picture ::" << imgPath << std::endl;
        }
        // 清理保存路径的内存
        free(buffer);

        return resDir;
    }

    void run()
    {
        std::string resourse_directory = preprocess();
        // std::string image_path = resourse_directory + "";

        // 01
        // course_01_read::read_show(resourse_directory + "cards.png");
        // course_01_read::read_camera(resourse_directory + "Megamind.avi");

        // 02
        //  course_02_basic::basic_functions(resourse_directory + "test_image.png");

        // 03
        //  course_03_resize::resize(resourse_directory + "cards.png");
        //  course_03_resize::crop(resourse_directory + "cards.png");

        // 04
        //  course_04_draw::shape();

        // 05
        //  course_05_perspective::warp(resourse_directory + "cards.png");

        // 06
        // course_06_color_detection::color_detection(resourse_directory + "test_image.png");

        // 07
        //  course_07_shape_detection::shape_detection(resourse_directory + "test_image.png");

        // 08
        // course_08_face_detection::face_detection(
        //     resourse_directory + "face_pic.png",
        //     resourse_directory + "haarcascade_frontalface_default.xml");

        // 09
        // course_09_virtual_painter::color_picker();
        course_09_virtual_painter::painter();
    }

}